package serverDB_classes;


import org.hibernate.Session;
/**
 * UserManager - manager the users in the Data Base
 * 						include: create user, save && update
 * @author Orit and Yoav
 *
 */
public class UserManager {
	
	/**
	 * create user with the given session and the detail of user:
	 * 						userName,password,first name,last name 
	 * @param session
	 * @param userName - email of the user
	 * @param password - password of the user
	 * @param firstName - first name of the user
	 * @param lastName - last name of the user
	 */
	public void createUser(Session session,String userName, String password,String firstName,
								String lastName) {
		UserData user=new UserData();
		user.setFirstName(firstName);
		user.setLastName(lastName);
		user.setPassword(password);
		user.setUserName(userName);
		saveUser(session,user);

	}
	
	/**
	 * save the user in the table
	 * @param session - open session 
	 * @param user - user to save
	 */
	 private void saveUser(Session session,UserData user){
	  session.save(user);
	  session.flush();
	 }
	
	 /**
	 * update user from the table in DB
	 * @param session - open session
	 * @param user - user to update
	 */
	 public void updateUser(Session session,UserData user){
	  session.update(user);
	  session.flush();
	 }
	
	 /**
	 * delete the user from table in DB
	 * @param session - open session 
	 * @param user - user to delete
	 */
	 public void deleteUser(Session session,UserData user) {
	  session.delete(user);
	  session.flush();
	 }
	}
